var app = require("lzbjpk_app");
cc.Class({
	extends: require(app.subGameName + "_BaseForm"),

	properties: {
		default_headIcon: cc.SpriteFrame,//默认头像图集
		icon_specialtype: [cc.SpriteFrame],
		typeSpriteFrame: [cc.SpriteFrame],


		bg_charging: cc.SpriteFrame,  //充电图标
		bg_electricity: [cc.SpriteFrame],  //电量状态
		icon_signal: [cc.SpriteFrame],     //信号图标

		//礼物
		giftPrefabs: [cc.Prefab],

		prefab_card: cc.Prefab,
		prefab_specialtype: cc.Prefab,
		UIInvitation: cc.Prefab,
	},

	OnCreateInit: function () {
		this.allPlayers = this.node.getChildByName("allPlayers");
		this.roomInfo = this.node.getChildByName("roomInfo");
		this.giftNode = this.node.getChildByName("giftNode");
		this.btn_caoZuoContainer = this.GetWndNode("allPlayers/pos1/caozuo");
		this.btn_voice = this.GetWndNode("roomBtnContainer/btn_all_voice");
		this.btn_chat = this.GetWndNode("roomBtnContainer/btn_all_chat");
		this.btn_change = this.GetWndNode("roomBtnContainer/btn_change");

		this.RoomMgr = app[app.subGameName.toUpperCase() + "RoomMgr"]();
		this.RoomPosMgr = app[app.subGameName.toUpperCase() + "RoomPosMgr"]();
		this.LogicBJPKRank = app[app.subGameName.toUpperCase() + "LogicRank"]();
		this.LogicBJPKGame = app[app.subGameName.toUpperCase() + "LogicGame"]();
		this.SceneManager = app[app.subGameName + "_SceneManager"]();
		this.BJPKDefine = app[app.subGameName.toUpperCase() + "Define"]();
		this.SDKManager = app[app.subGameName + "_SDKManager"]();
		this.UtilsWord = app[app.subGameName + "_UtilsWord"]();
		this.PokerCard = app[app.subGameName.toUpperCase() + "PokerCard"]();

		this.roomEnd = false;
		this.invitationNode = cc.instantiate(this.UIInvitation);
		this.node.addChild(this.invitationNode);

		// this.CreateCardNode();
		this.CreateSpecialTypeNode();

		for (let showPos = 1; showPos <= 5; showPos++) {
			let cardAniNode = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
			cardAniNode.getComponent(cc.Animation).on('finished', this.onFinishedCardAni.bind(null, showPos, this), this);
			let face_ani = this.GetWndNode("allPlayers/pos" + showPos + "/face_ani");
			face_ani.getComponent(cc.Animation).on('finished', this.onFinished.bind(null, face_ani), this);
		}

		this.RegEvent(this.GameTyepStringUp() + "_PosUpdate", this.Event_JoinRoom, this);//加入房间之后通知
		this.RegEvent(this.GameTyepStringUp() + "_PosReadyChg", this.Event_PosReadyChg, this);//玩家准备之后通知
		this.RegEvent(this.GameTyepStringUp() + "_DissolveRoom", this.Event_DissolveRoom, this);//解散房间
		this.RegEvent(this.GameTyepStringUp() + "_ChangePlayerNum", this.Event_ChangePlayerNum);//发起房间修改人数
		this.RegEvent(this.GameTyepStringUp() + "_StartVoteDissolve", this.Event_StartVoteDissolve);//发起房间结算投票
		this.RegEvent(this.GameTyepStringUp() + "_SetStart", this.Event_SetStart, this);//游戏开始
		this.RegEvent("PlayerOffline", this.Event_PlayerOffline, this);//玩家离线或者重新连上
		this.RegEvent(this.GameTyepStringUp() + "_PosOpCard", this.Event_PosOpCard, this);//会次出牌
		// this.RegEvent(this.GameTyepStringUp()+"_AllPosGetCard", this.Event_AllPosGetCard, this);//所有人抓一张牌
		this.RegEvent(this.GameTyepStringUp() + "_PosQiPai", this.Event_PosQiPai, this);//弃牌
		this.RegEvent(this.GameTyepStringUp() + "_PosCardReady", this.Event_PosCardReady, this);//比牌
		this.RegEvent(this.GameTyepStringUp() + "_SetEnd", this.Event_SetEnd, this);//小局结算
		this.RegEvent(this.GameTyepStringUp() + "_PosContinueGame", this.Event_PosContinueGame, this);//继续
		this.RegEvent(this.GameTyepStringUp() + "_RoomEnd", this.Event_RoomEnd, this);//房间结算
		this.RegEvent(this.GameTyepStringUp() + "_PosLeave", this.Event_PosLeave);
		this.RegEvent('ExitRoomSuccess', this.Event_ExitRoomSuccess, this);//成功退出房间

		this.RegEvent("ChatMessage", this.Event_ChatMessage, this);
		this.RegEvent('GameGift', this.Event_GameGift, this);//礼物

		this.RegEvent("ReadyRoomSportsPointChange", this.Event_SportsPointChange, this);//游戏未开始时竞技点增减提示
		//竞技点不足时通知
		this.RegEvent("SportsPointEnough", this.Event_SportsPointEnough, this);
		this.RegEvent("SportsPointNotEnough", this.Event_SportsPointNotEnough, this);
		this.RegEvent("CodeError", this.Event_CodeError, this);

		this.btn_voice.on("touchstart", this.Event_TouchStart, this);
		this.btn_voice.on("touchend", this.Event_TouchEnd, this);
		this.btn_voice.on("touchcancel", this.Event_TouchEnd, this);
	},
	OnShow: function () {
		//确保该玩家还在该房间内，否则强制退出房间
		let roomID = this.RoomMgr.GetEnterRoomID();
		console.log('=============UILZBJPKPlay OnShow GetRoomID=========')
		//获取房间Id
		app[app.subGameName + "_NetManager"]().SendPack(app.subGameName + ".C" + app.subGameName.toUpperCase() + "GetRoomID", {}, function (event) {
			if (event.roomID <= 0 || event.roomID != roomID) {
				app[app.subGameName + "Client"].ExitGame();
			}
		}, function (error) {
			app[app.subGameName + "Client"].ExitGame();
		});

		this.unscheduleAllCallbacks();
		this.CheckUpdateNotice();

		this.roomCfg = this.RoomMgr.GetEnterRoom().GetRoomConfig();
		if (this.roomCfg.clubId > 0 || this.roomCfg.unionId > 0) {
			this.invitationNode.active = true;
			this.invitationNode.getComponent(this.invitationNode.name).InitData(this.roomCfg.clubId, this.roomCfg.unionId, roomID);
		} else {
			this.invitationNode.active = false;
		}
		this.btn_voice.active = this.IsShowVoice();
		this.btn_chat.active = this.IsShowChat();
		this.btn_ready = this.GetZhunBeiBtn();
		this.btn_weixin = this.GetWeiXinBtn();
		this.btn_mowang = this.GetXianLiaoBtn();
		this.SceneManager.PlayMusic("qpRoomWaitStart");
		this.roomEnd = false;
		this.ShuaXining = false;
		this.SetRoomData();//设置房间信息
		this.InitCaoZuoBtn();//初始化操作按钮(根据数据初始化)
		// this.HideAllHead();//隐藏所有的玩家头像
		this.HideAllCardList();//隐藏所有的牌组
		this.HideAllLiXian();//隐藏离线sp
		this.InitAllHead();//设置玩家信息
		let room = this.RoomMgr.GetEnterRoom();
		this.playerNum = room.GetRoomConfigByProperty("playerNum");
		let changePlayerNum = room.GetRoomProperty("changePlayerNum");
		let endSec2 = changePlayerNum["endSec"];
		if (endSec2) {
			this.FormManager.ShowForm(app.subGameName + "_UIMessage03");
		} else {
			this.FormManager.CloseForm(app.subGameName + "_UIMessage03");
		}
		let state = room.GetRoomProperty("state");
		let posList = room.GetRoomProperty("posList");
		for (let i = 0; i < posList.length; i++) {
			let roomPos = posList[i];
			let showPos = this.Pos2Show(roomPos["pos"]);
			if (this.RoomMgr.unionId > 0) {
				let sportPoint = roomPos["sportsPoint"];
				this.SetPosSportPoint(showPos, sportPoint, true);
			} else {
				this.SetPosSportPoint(showPos, 0);
			}
		}
		if (state == 1) {
			let roomSet = this.GetBJPKRoomSet();
			let setState = roomSet.GetRoomProperty("state");
			this.HideAllIconOK();//隐藏ok手势
			this.HideCaoZuoBtn();
			let dissolveInfo = room.GetRoomProperty('dissolve');
			if (typeof(dissolveInfo) != "undefined") {
				if (dissolveInfo) {
					let posAgreeList = dissolveInfo.posAgreeList;
					if (0 != posAgreeList.length) {
						this.FormManager.ShowForm(app.subGameName + "_UIMessage02");
					}
				}
			}
			if (setState == 1) {
				let posInfo = roomSet.GetRoomProperty("posInfo");
				let setPosList = roomSet.GetRoomProperty("setPosList");
				let clientPos = room.GetRoomPosMgr().GetClientPos();
				for (let i = 0; i < posInfo.length; i++) {
					let setPos = posInfo[i];
					let pos = setPos["posID"];
					let showPos = this.Pos2Show(pos);
					let point = setPos["point"];
					let isQiPai = setPos["isQiPai"];
					let isReady = setPos["isReady"];
					let isCardReady = setPos["isCardReady"];
					let abandonFlag = setPos["abandonFlag"];
					let isPlaying = setPos["isPlaying"];
					let playerRanked = setPos["playerRanked"];
					let cardAniNode = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
					this.HideOrShowPosCardList(showPos, true);
					for (let j = 0; j < cardAniNode.children.length; j++) {
						cardAniNode.children[j].active = true;
						cardAniNode.children[j].getChildByName("poker_back").active = true;
					}
					this.SetPosPoint(showPos, point);//显示分数point
					this.HideOrShowPosQiPai(showPos, abandonFlag);//显示弃牌
					if (!isCardReady) {//牌还没有准备好
						if (clientPos == pos) {
							let uiPath = `game/${app.subGameName.toUpperCase()}/ui/UI${app.subGameName.toUpperCase()}Rank`;
							this.FormManager.ShowForm(uiPath);
							//显示牌
						} else {
							this.HideOrShowPosBiPai(showPos, "理牌中...");
						}
					} else {
						if (clientPos == pos) {
							//显示手牌
							let shouCard = [];
							for (let k in playerRanked) {
								let cards = playerRanked[k];
								let sortCards = this.GetSortCard(cards);
								for (let l = 0; l < sortCards.length; l++) {
									shouCard.push(sortCards[l]);
								}
							}
							for (let m = 0; m < shouCard.length; m++) {
								this.ShowCard(shouCard[m], cardAniNode.children[m]);
							}
						} else {
							this.HideOrShowPosBiPai(showPos, "比牌中...");
						}
					}
				}
			} else if (setState == 2) {
				//gameReady
				let clientPos = room.GetRoomPosMgr().GetClientPos();
				let rankingResult = this.GetBJPKRoomSet().GetRoomSetProperty("setEnd")["sRankingResult"];
				let cardList = [rankingResult["pCard1"], rankingResult["pCard2"], rankingResult["pCard3"]];
				let playerResults = rankingResult["playerResults"];
				// let playerResults = rankingResult["posResultList"];
				let rewardsDict = this.GetBJPKRoomSet().GetRoomProperty("rewardsDict");

				for (let i = 0; i < cardList.length; i++) {
					for (let j = 0; j < cardList[i].length; j++) {
						let dunCard = cardList[i][j];
						let posID = dunCard["posID"];
						let cards = dunCard["cards"];
						let abandonFlag = false;
						if (cards.length == 0) {
							cards = [0, 0, 0];
							abandonFlag = true;
						}
						let rewards = rewardsDict[posID]["rewards"];
						let sportPoint = rewardsDict[posID]["sportsPoint"];
						let rankingEnum = dunCard["rankingEnum"];
						let score = dunCard["score"];
						let showPos = this.Pos2Show(posID);
						let cardNodeList = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
						this.HideOrShowPosCardList(showPos, true);
						this.HideOrShowPosQiPai(showPos, abandonFlag);//显示弃牌
						let sortCards = this.GetSortCard(cards);
						for (let k = 0; k < sortCards.length; k++) {
							if (i == 0) {
								this.ShowCard(sortCards[k], cardNodeList.children[k]);
								this.HideOrShowFirstScore(showPos, score, rankingEnum);
							} else if (i == 1) {
								this.ShowCard(sortCards[k], cardNodeList.children[k + 3]);
								this.HideOrShowSecondScore(showPos, score, rankingEnum);
							} else if (i == 2) {
								this.ShowCard(sortCards[k], cardNodeList.children[k + 6]);
								this.HideOrShowThirdScore(showPos, score, rankingEnum);
							}
						}
						let wndPath = "allPlayers/pos" + showPos + "/score/cardtypelayout/";
						for (let i = 0; i < rewards.length; i++) {
							let reward = rewards[i];
							this.SetWndProperty(wndPath + reward, "active", true);
						}
						this.SetWndProperty("allPlayers/pos" + showPos + "/score/lb_sportpoint", "active", this.RoomMgr.unionId > 0);
						this.SetWndProperty("allPlayers/pos" + showPos + "/score/lb_sportpoint", "text", "赛：" + sportPoint);
					}
				}
				for (let l = 0; l < playerResults.length; l++) {
					let showPos = this.Pos2Show(l);
					// this.HideOrShowAllScore(showPos, playerResults[l]["score"]);
					this.HideOrShowAllScore(showPos, playerResults[l]["allScore"]);
					this.SetPosPoint(showPos, playerResults[l]["roomScore"]);
				}
				for (let m = 0; m < posList.length; m++) {
					let gameReady = posList[m]["gameReady"];
					let pos = posList[m]["pos"];
					let showPos = this.Pos2Show(pos);
					if (clientPos == pos && !gameReady) {
						this.ShowContinueBtn();
					}
					this.HidePosIconOk(showPos, gameReady);
				}
				/*for (let m = 0; m < posList.length; m++) {
					let gameReady = posList[m]["gameReady"];
					let pos = posList[m]["pos"];
					let showPos = this.Pos2Show(pos);
					if (gameReady) {
						this.HideAllPosScore(showPos);
						this.HideOrShowPosCardList(showPos, false);
						this.HideOrShowPosQiPai(showPos, false);
						this.HidePosSpecialType(showPos);
					}
				}*/
				// this.ShowSpecialType();
				// this.ShowContinueBtn();
			}
		}
		//显示房间信息
		let laWanfa = this.roomInfo.getChildByName("wanfa");
		laWanfa.getComponent("cc.Label").string = this.playerNum +"人，"+ this.WanFa();
		//电量信号
		if (cc.sys.isNative) {
			app[app.subGameName + "Client"].RegEvent("EvtBatteryLevel", this.OnEvent_BatteryLevel, this);
			app[app.subGameName + "_NativeManager"]().CallToNative("registerReceiver", []);
		}
		app[app.subGameName + "Client"].RegEvent("EvtSpeedTest", this.OnEvent_SpeedTest, this);
		this.ShowPlayerReady(room);
	},
	//位置离开
	Event_PosLeave: function (event) {
		let room = this.RoomMgr.GetEnterRoom();
		if (!room) {
			console.error("Event_PosLeave not enter room");
			return
		}
		let argDict = event;
		let pos = argDict["pos"];
		let clientPos = room.GetRoomPosMgr().GetClientPos();
		//如果是客户端玩家并且是被T了
		if (argDict["beKick"] && clientPos == pos) {
			if (argDict["kickOutTYpe"] == 2) {
				this.SetWaitForConfirm("MSG_BeKick", this.ShareDefine.ConfirmOK, [argDict.msg]);
			} else if (argDict["kickOutTYpe"] == 3) {
				this.SetWaitForConfirm('MSG_BeKick', this.ShareDefine.ConfirmOK, ["由于长时间未准备，您已被请出房间"]);
			} else {
				this.SetWaitForConfirm("UIPlay_BeKick", this.ShareDefine.ConfirmOK);
			}
		}

		let posHead = this.allPlayers.getChildByName('pos' + this.Pos2Show(pos));
		posHead.active = false;

	},
	//设置房间信息
	SetRoomData: function () {
		let room = this.RoomMgr.GetEnterRoom();
		let roomKey = room.GetRoomProperty("key");
		let current = room.GetRoomConfigByProperty("setCount");
		let setID = room.GetRoomProperty("setID");
		this.SetRoomID(setID, current);
		let node_roomKey = this.roomInfo.getChildByName('lb_roomkey');
		node_roomKey.getComponent("cc.Label").string = "房间号：" + roomKey;
		let fangjian = room.GetRoomConfigByProperty("fangjian");
		if (fangjian.indexOf(0) <= -1) {
			this.btn_change.active = false;
		} else {
			if (setID == 0) {
				this.btn_change.active = true;
			} else {
				this.btn_change.active = false;
			}
		}
	},

	//设置当前第几局和总局数
	SetRoomID: function (setID, current) {
		let node_setcount = this.roomInfo.getChildByName('lb_setcount');
		node_setcount.getComponent("cc.Label").string = setID + "/" + current + "局";
	},

	HideAllHead: function () {
		for (let i = 0; i < this.allPlayers.children.length; i++) {
			this.allPlayers.children[i].active = false;
		}
	},
	Click_btn_change: function () {
		//this.FormManager.ShowForm('UIChangePlayerNum');
		let roomID = this.RoomMgr.GetEnterRoomID();
		let that = this;
		app[app.subGameName + "_NetManager"]().SendPack(app.subGameName + ".C" + app.subGameName.toUpperCase() + "ChangePlayerNum", {"roomID": roomID}, function (success) {

			},
			function (error) {
				let msg = error.Msg;
				that.ShowSysMsg(msg);
			});
	},
	click_share: function (type) {
		let room = this.RoomMgr.GetEnterRoom();
		var WeChatShare = app[app.subGameName + "_WeChatManager"]().WeChatShare(app.subGameName);
		let title = null;
		if (WeChatShare['special']) {
			title = WeChatShare['special'];
		} else {
			title = WeChatShare['title'];
		}
		let weChatAppShareUrl = WeChatShare['url'];
		let setCount = room.GetRoomConfigByProperty("setCount");  //多少局
		let roomKey = room.GetRoomProperty("key");  //房间号
		let createType = room.GetRoomProperty("createType");
		let autoCardIdx = room.GetRoomConfigByProperty("paymentRoomCardType");
		let payType = '';

		let allPlayerInfo = room.GetRoomPosMgr().GetRoomAllPlayerInfo();
		let joinPlayerCount = room.GetRoomPosMgr().GetRoomPlayerCount();  //几人场
		let nowJoin = 0;
		let gamedesc = "";

		for (let i = 0; i < joinPlayerCount; i++) {
			if (allPlayerInfo[i].pid > 0)
				nowJoin++;
		}
		let que = joinPlayerCount - nowJoin;
		title = title.replace('{房间号}', roomKey);
		if (createType == 3) {
			let clubName = room.GetRoomProperty("clubName");
			title = "[" + clubName + "]" + "亲友团," + roomKey + " " + nowJoin + "等" + que + "进团";
		} else {
			title = "开房邀请:" + roomKey + " " + nowJoin + "等" + que;
		}
		//this.FormManager.ShowForm('UIRoomCopy',roomKey,title,gamedesc,weChatAppShareUrl);
		if (type == 'dingding') {
			this.SDKManager.ShareDD(title, gamedesc, weChatAppShareUrl);
		} else if (type == 'xiangliao') {
			this.SDKManager.ShareXiangLiao(title, gamedesc, weChatAppShareUrl);
		} else if (type == 'mowang') {
			this.SDKManager.ShareMW(title, gamedesc, weChatAppShareUrl);
		} else if (type == 'weixin') {
			this.SDKManager.Share(title, gamedesc, weChatAppShareUrl, "0");
		}
	},
	SendHttpRequest: function (serverUrl, argString, requestType, sendPack) {

		var url = [serverUrl, argString].join("")

		var dataStr = JSON.stringify(sendPack);

		//每次都实例化一个，否则会引起请求结束，实例被释放了
		var httpRequest = new XMLHttpRequest();

		httpRequest.timeout = 2000;


		httpRequest.open(requestType, url, true);
		//服务器json解码
		httpRequest.setRequestHeader("Content-Type", "application/json");
		var that = this;
		httpRequest.onerror = function () {
			console.error("httpRequest.error:%s", url);
			that.OnConnectHttpFail(serverUrl, httpRequest.readyState, httpRequest.status);
		};
		httpRequest.ontimeout = function () {

		};
		httpRequest.onreadystatechange = function () {
			//执行成功
			if (httpRequest.status == 200) {
				if (httpRequest.readyState == 4) {
					that.OnReceiveHttpPack(serverUrl, httpRequest.responseText);
				}
			}
			else {
				that.OnConnectHttpFail(serverUrl, httpRequest.readyState, httpRequest.status);
				console.error("onreadystatechange(%s,%s)", httpRequest.readyState, httpRequest.status);
			}
		};
		httpRequest.send(dataStr);

	},
	OnReceiveHttpPack: function (serverUrl, httpResText) {
		try {
			let serverPack = JSON.parse(httpResText);
			if (serverPack[0]["url_short"]) {
				this.weixin_weChatAppShareUrl = serverPack[0]["url_short"];
			}
			this.Share();
		}
		catch (error) {

		}
	},
	OnConnectHttpFail: function (serverUrl, readyState, status) {
		this.Share();
	},
	Share: function () {
		if (this.weixin_gamedesc) {
			this.SDKManager.ShareText(this.weixin_title + "\n" + this.weixin_gamedesc + "\n" + "点击链接直达:" + this.weixin_weChatAppShareUrl, "0");
		} else {
			this.SDKManager.ShareText(this.weixin_title + "\n" + "点击链接直达:" + this.weixin_weChatAppShareUrl, "0");
		}
	},
	//初始化所有玩家的信息
	InitAllHead: function () {
		this.HideAllHead();
		let players = this.RoomMgr.GetEnterRoom().GetRoomProperty('posList');
		let ownerID = this.GetBJPKRoom().GetRoomProperty("ownerID");
		let jieSanBtn = this.GetJieSanBtn();
		console.log("InitAllHead", players);
		for (let i = 0; i < players.length; i++) {
			if (!players[i].pid) {
				console.log("continueHead", players[i]);
				continue;
			}
			let player = players[i];
			if (ownerID == player["pid"]) {
				player["isFangZhu"] = true;
				jieSanBtn.active = true;
			} else {
				player["isFangZhu"] = false;
				jieSanBtn.active = false;
			}
			let showPos = this.Pos2Show(player["pos"]);
			console.log("showPos", showPos);
			this.ShowPosLiXian(showPos, player["isLostConnect"]);
			this.InitPosHead(showPos, players[i]);
		}
	},
	//初始化操作按钮
	InitCaoZuoBtn: function () {
		let weiXinBtn = this.GetWeiXinBtn();
		let xianLiaoBtn = this.GetXianLiaoBtn();
		let zhunBeiBtn = this.GetZhunBeiBtn();
		let continueBtn = this.GetContinueBtnBtn();
		weiXinBtn.active = true;
		xianLiaoBtn.active = true;
		zhunBeiBtn.active = true;
		continueBtn.active = false;
	},

	//隐藏操作按钮
	HideCaoZuoBtn: function () {
		let weiXinBtn = this.GetWeiXinBtn();
		let xianLiaoBtn = this.GetXianLiaoBtn();
		let zhunBeiBtn = this.GetZhunBeiBtn();
		let continueBtn = this.GetContinueBtnBtn();
		weiXinBtn.active = false;
		xianLiaoBtn.active = false;
		zhunBeiBtn.active = false;
		continueBtn.active = false;
	},
	ShowContinueBtn: function () {
		let continueBtn = this.GetContinueBtnBtn();
		continueBtn.active = true;
	},

	//隐藏跟注按钮
	HideGenZhuBtn: function () {
		let genzhuContainer = this.btn_caoZuoContainer.getChildByName("genzhuContainer");
		genzhuContainer.active = false;
	},
	//初始化等待label
	InitDengdaiqitaLb: function () {
		/*let DengdaiqitaLb = this.btn_caoZuoContainer.getChildByName("lb_dengdaiqita");
		DengdaiqitaLb.active = true;*/
	},
	//初始化等待label
	HideDengdaiqitaLb: function () {
		let DengdaiqitaLb = this.btn_caoZuoContainer.getChildByName("lb_dengdaiqita");
		DengdaiqitaLb.active = false;
	},
	OnEvent_BatteryLevel: function (event) {
		let power = event['Level'];
		let status = event['status'];
		if (power <= 20) {
			this.node.getChildByName('right_top').getChildByName('lb_power').color = cc.color(247, 14, 38);
		} else {
			this.node.getChildByName('right_top').getChildByName('lb_power').color = cc.color(255, 255, 255);
		}
		this.node.getChildByName('right_top').getChildByName('lb_power').getComponent(cc.Label).string = power + "%";
		if (status == 2) {
			//充电中
			this.node.getChildByName('right_top').getChildByName('bg_power').getComponent(cc.Sprite).spriteFrame = this.bg_charging;
		} else {
			if (power <= 10) {
				this.node.getChildByName('right_top').getChildByName('bg_power').getComponent(cc.Sprite).spriteFrame = this.bg_electricity[0];
			} else if (power <= 20) {
				this.node.getChildByName('right_top').getChildByName('bg_power').getComponent(cc.Sprite).spriteFrame = this.bg_electricity[1];
			} else if (power <= 40) {
				this.node.getChildByName('right_top').getChildByName('bg_power').getComponent(cc.Sprite).spriteFrame = this.bg_electricity[2];
			} else if (power <= 60) {
				this.node.getChildByName('right_top').getChildByName('bg_power').getComponent(cc.Sprite).spriteFrame = this.bg_electricity[3];
			} else if (power < 100) {
				this.node.getChildByName('right_top').getChildByName('bg_power').getComponent(cc.Sprite).spriteFrame = this.bg_electricity[4];
			} else {
				this.node.getChildByName('right_top').getChildByName('bg_power').getComponent(cc.Sprite).spriteFrame = this.bg_electricity[5];
			}
		}

	},

	OnEvent_SpeedTest: function (event) {
		let YanCi = event['yanci'];
		let signal = this.node.getChildByName('right_top').getChildByName('signal');
		if (YanCi < 100) {
			signal.getChildByName('lb_signal').getComponent(cc.Label).string = YanCi + 'ms';
			signal.getChildByName('lb_signal').color = cc.color(144, 227, 83);
			signal.getChildByName('bg_signal').getComponent(cc.Sprite).spriteFrame = this.icon_signal[5];
		} else if (YanCi < 300) {
			signal.getChildByName('lb_signal').getComponent(cc.Label).string = YanCi + 'ms';
			signal.getChildByName('lb_signal').color = cc.color(144, 227, 83);
			signal.getChildByName('bg_signal').getComponent(cc.Sprite).spriteFrame = this.icon_signal[4];
		} else if (YanCi < 600) {
			signal.getChildByName('lb_signal').getComponent(cc.Label).string = YanCi + 'ms';
			signal.getChildByName('lb_signal').color = cc.color(213, 203, 43);
			signal.getChildByName('bg_signal').getComponent(cc.Sprite).spriteFrame = this.icon_signal[3];
		} else if (YanCi < 1000) {
			signal.getChildByName('lb_signal').getComponent(cc.Label).string = YanCi + 'ms';
			signal.getChildByName('lb_signal').color = cc.color(254, 173, 80);
			signal.getChildByName('bg_signal').getComponent(cc.Sprite).spriteFrame = this.icon_signal[2];
		} else if (YanCi < 5000) {
			signal.getChildByName('lb_signal').getComponent(cc.Label).string = Math.floor(YanCi / 1000) + 's';
			signal.getChildByName('lb_signal').color = cc.color(234, 49, 60);
			signal.getChildByName('bg_signal').getComponent(cc.Sprite).spriteFrame = this.icon_signal[1];
		} else {
			signal.getChildByName('lb_signal').getComponent(cc.Label).string = '>5s';
			signal.getChildByName('lb_signal').color = cc.color(234, 49, 60);
			signal.getChildByName('bg_signal').getComponent(cc.Sprite).spriteFrame = this.icon_signal[0];
		}
	},
	//s->c位置
	Pos2Show: function (pos) {
		let RoomPosMgr = this.RoomMgr.GetEnterRoom().GetRoomPosMgr();
		let clientPos = RoomPosMgr.GetClientPos();//自己1
		let downPos = RoomPosMgr.GetClientDownPos();//下一个2
		let facePos = RoomPosMgr.GetClientFacePos();//对面3
		let upPos = RoomPosMgr.GetClientUpPos();//4
		let fivePos = RoomPosMgr.GetClientFivePos();//最后一个5
		if (pos == clientPos) {
			return 1;
		} else if (pos == downPos) {
			return 2;
		} else if (pos == facePos) {
			return 3;
		} else if (pos == upPos) {
			return 4;
		} else if (pos == fivePos) {
			return 5;
		}
		return -1;
	},
	//c->s位置
	Show2Pos: function (showPos) {
		if (this.Pos2Show(0) == showPos) {
			return 0;
		}
		if (this.Pos2Show(1) == showPos) {
			return 1;
		}
		if (this.Pos2Show(2) == showPos) {
			return 2;
		}
		if (this.Pos2Show(3) == showPos) {
			return 3;
		}
		if (this.Pos2Show(4) == showPos) {
			return 4;
		}
	},
	//玩家加入游戏
	//加入房间
	Event_JoinRoom: function (event) {
		console.log("=====加入房间Event_JoinRoom===", event);
		let room = this.RoomMgr.GetEnterRoom();
		this.ShowPlayerReady(room);
		let serverPack = event;
		let pos = serverPack.pos;
		let data = serverPack.posInfo;
		this.InitPosHead(this.Pos2Show(pos), data);
	},
	//收到解散房间
	Event_StartVoteDissolve: function (event) {
		this.FormManager.ShowForm(app.subGameName + "_UIMessage02");
	},
	//玩家准备后显示
	Event_PosReadyChg: function (event) {
		console.log("========UILZBJPKPlay.Event_PosReadyChg 玩家准备后显示==================", event);
		let room = this.RoomMgr.GetEnterRoom();
		this.ShowPlayerReady(room);
		let serverPack = event;
		let pos = serverPack["pos"];
		let isReady = serverPack["isReady"];
		let showPos = this.Pos2Show(pos);
		/*if (isReady) {//玩家准备后隐藏ok手势
			this.HidePosIconOk(showPos, false);
		}*/
		this.HidePosIconOk(showPos, isReady);
	},
	//房间解散
	Event_DissolveRoom: function (event) {
		let argDict = event;
		let ownnerForce = argDict["ownnerForce"];

		//未开启房间游戏时才会触发
		if (ownnerForce) {
			let room = this.RoomMgr.GetEnterRoom();
			//如果是房主主动接撒直接退出
			if (room && room.IsClientIsOwner()) {
				app[app.subGameName + "Client"].ExitGame();
			}
			else {
				this.SetWaitForConfirm('OwnnerForceRoom', this.ShareDefine.ConfirmOK);
			}
		} else if (event.dissolveNoticeType == 1) {
			this.SetWaitForConfirm('SportsPointDissolveRoom', this.ShareDefine.ConfirmOK, [event.msg]);
		} else if (event.dissolveNoticeType == 3) {
			this.SetWaitForConfirm('MSG_BeDissolve', this.ShareDefine.ConfirmOK, [event.msg]);
		} else {
			let state = this.RoomMgr.GetEnterRoom().GetRoomProperty("state");
			//如果没有打完一局不会下发roomend,直接显示2次弹框
			if (state != this.ShareDefine.RoomState_End) {
				this.SetWaitForConfirm('DissolveRoom', this.ShareDefine.ConfirmOK);
				this.FormManager.CloseForm(app.subGameName + "_UIMessage02");
			}
			//如果有roomend数据显示 结果界面
			else {
				this.FormManager.CloseForm(app.subGameName + "_UIMessage02");
				this.ShowDanJuForm();
			}

		}
	},
	//收到切换人数房间
	Event_ChangePlayerNum: function (event) {
		this.FormManager.ShowForm(app.subGameName + "_UIMessage03");
	},
	//游戏开始
	Event_SetStart: function (event) {
		console.log("===============UILZBJPKPlay Event_SetStart========PLay___游戏开始Event_SetStart", event);
		this.SceneManager.PlayMusic("qpRoomStart");

		this.roomEnd = false;
		let serverPack = event;
		let setInfo = serverPack["setInfo"];
		let setPosList = setInfo["posInfo"]; //手牌信息
		let room = this.RoomMgr.GetEnterRoom();
		let setID = setInfo["setID"];
		let current = room.GetRoomConfigByProperty("setCount");

		this.SetRoomID(setID, current);//游戏开始更新局数
		this.OnSetStart(setPosList);//初始化牌面
		this.HideCaoZuoBtn();//隐藏操作按钮
		this.HideAllIconOK();//隐藏ok手势
		this.HideAllBiPai(); //隐藏状态(比牌中/理牌中)
		this.HideAllScore(); //清空分数状态
		this.HideAllSpecialType();
		this.GetJieSanBtn().active = false;  //隐藏操作按钮（邀请好友按钮）
		this.GetExitBtn().active = false;
	},
	Event_PlayerOffline: function (event) {
		console.log("玩家离线Event_PlayerOffline", event);
		let roomPosMgr = this.GetBJPKRoomPosMgr();
		let pid = event.pid;
		let pos = roomPosMgr.PidGetPos(pid);
		let isLostConnect = event.isLostConnect;
		let showPos = this.Pos2Show(pos);
		this.ShowPosLiXian(showPos, isLostConnect);
	},
	

	//初始化牌
	OnSetStart: function (setPosList) {
		//发牌动作
		for (let i = 0; i < setPosList.length; i++) {
			let showPos = this.Pos2Show(i);
			//显示玩家pos 节点
			this.SetWndProperty("allPlayers/pos" + showPos, "active", true);
			this.HideOrShowPosQiPai(showPos, false);

			//显示牌背
			let cardAniNode = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
			for (let j = 0; j < cardAniNode.children.length; j++) {
				cardAniNode.children[j].getChildByName("poker_back").active = true; //显示牌背
				cardAniNode.children[j].active = true;
			}
			cardAniNode.active = true;

			cardAniNode.getComponent(cc.Animation).play("cardAni");
		}

		//进入理牌阶段，创建UILZBJPKRank 预制体
		this.scheduleOnce(() => {
			let uiPath = `game/${app.subGameName.toUpperCase()}/ui/UI${app.subGameName.toUpperCase()}Rank`;
			this.FormManager.ShowForm(uiPath);
		}, 0.8);
	},
	onFinished: function (faceAni) {
		faceAni.active = false;
	},
	onFinishedCardAni: function (showPos, that) {
		that.HideOrShowPosBiPai(showPos, "理牌中...");
	},
	ShowKanPai: function (showPos, privateCards) {
		/*let posHead = this.allPlayers.getChildByName('pos' + showPos);
		let cardList = posHead.getChildByName('cardList');
		for (let i = 0; i < privateCards.length; i++) {
			let cardValue = privateCards[i];
			let cardNode = cardList.children[i];
			this.ShowCard(cardValue, cardNode, true);
		}*/
	},
	ShowCard: function (cardValue, cardNode, isShowIcon1) {
		cardNode.active = true;
		let realValue = 0;
		if (cardValue > 500) {
			realValue = cardValue - 500;
		}
		else {
			realValue = cardValue;
		}
		cardNode.active = true;
		if (cardValue == 0) {
			cardNode.getChildByName("poker_back").active = true;
			return;
		} else {
			cardNode.getChildByName("poker_back").active = false;
		}
		this.PokerCard.GetPokeCard(realValue, cardNode, isShowIcon1, true);
	},
	//回合消息
	Event_PosOpCard: function (event) {
		let argDict = event;
		let roomSet = this.GetBJPKRoomSet();
		console.log("回合消息Event_PosOpCard", argDict);
		let pos = argDict["pos"];
		let chipValue = argDict["chip"];
		let showPos = this.Pos2Show(pos);
		let chip = roomSet.GetPosChipValue(pos);
		roomSet.SetCurChipValue(chipValue);
	},
	//玩家弃牌结果
	Event_PosQiPai: function (event) {
		let argDict = event;
		console.log("玩家弃牌结果 Event_PosQiPai", argDict);
		let clientPos = this.GetBJPKRoomPosMgr().GetClientPos();
		let posId = argDict["posID"];
		let abandonFlag = argDict["abandonFlag"];
		let showPos = this.Pos2Show(posId);
		this.HideOrShowPosQiPai(showPos, abandonFlag);
		// this.HideOrShowPosCardList(showPos, true);
		let cardList = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
		for (let i = 0; i < cardList.children.length; i++) {
			cardList.children[i].getChildByName("poker_back").active = true;
			// cardList.children[i].scaleX = 1;
		}
		this.HideOrShowPosBiPai(showPos, "");
		// cardList.active = true;
		if (abandonFlag && clientPos == posId) {
			let uiPath = `game/${app.subGameName.toUpperCase()}/ui/UI${app.subGameName.toUpperCase()}Rank`;
			this.FormManager.CloseForm(uiPath);
		}
	},
	//玩家比牌
	Event_PosCardReady: function (event) {
		let argDict = event;
		console.log("玩家比牌 Event_PosCardReady", argDict);
		let clientPos = this.GetBJPKRoomPosMgr().GetClientPos();
		this.ShowPosCardReady(argDict, clientPos, this);
	},
	ShowPosCardReady: function (argDict, clientPos, that) {
		//如果是自己显示自己的牌
		let posId = argDict["posID"];
		let ranked = argDict["ranked"];
		let showPos = that.Pos2Show(posId);
		if (clientPos == posId) {//玩家自己
			//显示自己的手牌
			let first = ranked["first"];
			let second = ranked["second"];
			let third = ranked["third"];
			let cardValueList = that.GetDownListCard(first, second, third);
			let cardList = that.GetWndNode("allPlayers/pos1/cardList");
			for (let i = 0; i < cardList.children.length; i++) {
				// cardList.children[i].scale = 1;
				let cardValue = cardValueList[i];
				that.ShowCard(cardValue, cardList.children[i]);
			}
			that.HideOrShowPosBiPai(showPos, "");
			let uiPath = `game/${app.subGameName.toUpperCase()}/ui/UI${app.subGameName.toUpperCase()}Rank`;
			console.log('======uiPath========',uiPath)
			that.FormManager.CloseForm(uiPath);
		} else {
			// let isReady = argDict["isReady"];
			that.HideOrShowPosBiPai(showPos, "比牌中...");
			that.HideOrShowPosCardList(showPos, true);
		}
	},
	GetDownListCard: function (first, second, third) {
		let dun1 = [];
		let dun2 = [];
		let dun3 = [];
		if (first.length == 0) {
			let DUN1 = this.LogicBJPKRank.getDunListByType("DUN1");
			if (DUN1.length == 0) {
				let cardList = [0, 0, 0, 0, 0, 0, 0, 0, 0];
				return cardList;
			} else {
				dun1 = DUN1;
				dun2 = this.LogicBJPKRank.getDunListByType("DUN2");
				dun3 = this.LogicBJPKRank.getDunListByType("DUN3");
			}
		} else {
			dun1 = first;
			dun2 = second;
			dun3 = third;
		}

		let downListCard = [];
		let sort1 = dun1;
		this.LogicBJPKGame.SortCardByMin(dun1);
		//23A
		if (this.LogicBJPKGame.GetCardValue(dun1[0]) == 2 &&
			this.LogicBJPKGame.GetCardValue(dun1[1]) == 3 &&
			this.LogicBJPKGame.GetCardValue(dun1[2]) == 14) {
			sort1.unshift(dun1[2]);
			sort1.pop();
		} else if (this.LogicBJPKGame.GetCardValue(dun1[0]) < this.LogicBJPKGame.GetCardValue(dun1[1]) &&
			this.LogicBJPKGame.GetCardValue(dun1[1]) == this.LogicBJPKGame.GetCardValue(dun1[2])) {
			sort1.reverse();
		}
		let sort2 = dun2;
		this.LogicBJPKGame.SortCardByMin(dun2);
		//23A
		if (this.LogicBJPKGame.GetCardValue(dun2[0]) == 2 &&
			this.LogicBJPKGame.GetCardValue(dun2[1]) == 3 &&
			this.LogicBJPKGame.GetCardValue(dun2[2]) == 14) {
			sort2.unshift(dun2[2]);
			sort2.pop();
		} else if (this.LogicBJPKGame.GetCardValue(dun2[0]) < this.LogicBJPKGame.GetCardValue(dun2[1]) &&
			this.LogicBJPKGame.GetCardValue(dun2[1]) == this.LogicBJPKGame.GetCardValue(dun2[2])) {
			sort2.reverse();
		}
		let sort3 = dun3;
		this.LogicBJPKGame.SortCardByMin(dun3);
		//23A
		if (this.LogicBJPKGame.GetCardValue(dun3[0]) == 2 &&
			this.LogicBJPKGame.GetCardValue(dun3[1]) == 3 &&
			this.LogicBJPKGame.GetCardValue(dun3[2]) == 14) {
			sort3.unshift(dun3[2]);
			sort3.pop();
		} else if (this.LogicBJPKGame.GetCardValue(dun3[0]) < this.LogicBJPKGame.GetCardValue(dun3[1]) &&
			this.LogicBJPKGame.GetCardValue(dun3[1]) == this.LogicBJPKGame.GetCardValue(dun3[2])) {
			sort3.reverse();
		}
		for (let i = 0; i < sort1.length; i++) {
			downListCard.push(sort1[i]);
		}
		for (let j = 0; j < sort2.length; j++) {
			downListCard.push(sort2[j]);
		}
		for (let k = 0; k < sort3.length; k++) {
			downListCard.push(sort3[k]);
		}
		return downListCard;
	},
	GetSortCard: function (cards) {
		let array = cards;
		this.LogicBJPKGame.SortCardByMin(cards);
		//23A 667 566
		if (this.LogicBJPKGame.GetCardValue(array[0]) == 2 &&
			this.LogicBJPKGame.GetCardValue(array[1]) == 3 &&
			this.LogicBJPKGame.GetCardValue(array[2]) == 14) {
			array.unshift(cards[2]);
			array.pop();
		}
		if (this.LogicBJPKGame.GetCardValue(array[0]) < this.LogicBJPKGame.GetCardValue(array[1]) &&
			this.LogicBJPKGame.GetCardValue(array[1]) == this.LogicBJPKGame.GetCardValue(array[2])) {
			array.reverse();
		}
		return array;
	},
	//小局结束
	Event_SetEnd: function (event) {

		let argDict = event;
		console.log("小局结束Event_SetEnd", argDict);
		let playerResults = argDict["sRankingResult"]["playerResults"];
		for (let i = 0; i < playerResults.length; i++) {
			let posID = playerResults[i]["posID"];
			let showPos = this.Pos2Show(posID);
			this.SetWndProperty("allPlayers/pos" + showPos, "active", true);
		}
		let uiPath = `game/${app.subGameName.toUpperCase()}/ui/UI${app.subGameName.toUpperCase()}Rank`;
		this.FormManager.CloseForm(uiPath);
		this.GetExitBtn().active = true;

		// let soundName = this.BJPKDefine.SoundPath + "startbipai";
		this.SoundManager.PlaySound("startbipai");
		/*let setEnd = argDict["setEnd"];
		let endTime = argDict["endTime"];
		let setId = argDict["setId"];
		let posEndList = argDict["posEndList"];
		let uiPath = `game/${app.subGameName.toUpperCase()}/ui/UI${app.subGameName.toUpperCase()}DanJu`;
		this.FormManager.ShowForm("uiPath, argDict);*/
		let rankingResult = this.GetBJPKRoomSet().GetRoomSetProperty("setEnd")["sRankingResult"];
		//从order最大的开始翻牌显示数据
		let playCount = rankingResult["playerResults"].length;
		// let playCount = rankingResult["posResultList"].length;
		let count = playCount - 1;
		for (let pos = 1; pos <= playCount; pos++) {
			this.HideOrShowPosBiPai(pos, "");
		}
		let cardList = [rankingResult["pCard1"], rankingResult["pCard2"], rankingResult["pCard3"]];
		// this.FaNPaiFirst(count, cardList, playCount, this);
		let clientPos = this.GetBJPKRoomPosMgr().GetClientPos();
		this.FaNPaiAllFirst(clientPos, cardList);
	},
	/*FaNPaiFirst: function (count, cardList, playCount, that) {
		if (count < 0) {
			count = playCount - 1;
			that.FaNPaiSecond(count, cardList, playCount, that);
			return;
		}
		let clientPos = this.GetBJPKRoomPosMgr().GetClientPos();
		let dunCard1 = cardList[0][count];
		let posID = dunCard1["posID"];
		let cards = dunCard1["cards"];
		this.LogicBJPKGame.SortCardByMin(cards);
		let rankingEnum = dunCard1["rankingEnum"];
		let score = dunCard1["score"];
		let showPos = that.Pos2Show(posID);
		let cardNodeList = that.GetWndNode("allPlayers/pos" + showPos + "/cardList");
		let action = cc.sequence(cc.scaleTo(2, 1, 1), cc.callFunc(function () {
			if (clientPos != posID) {
				for (let i = 0; i < cards.length; i++) {
					// cardNodeList.children[i].scale = 1;
					that.ShowCard(cards[i], cardNodeList.children[i]);
				}
			}
			that.HideOrShowFirstScore(showPos, score, rankingEnum);
			count--;
			that.FaNPaiFirst(count, cardList, playCount, that);
		}));
		for (let j = 0; j < 3; j++) {
			cardNodeList.children[j].runAction(action);
		}
	},
	FaNPaiSecond: function (count, cardList, playCount, that) {
		if (count < 0) {
			count = playCount - 1;
			that.FaNPaiThird(count, cardList, playCount, that);
			return;
		}
		let clientPos = this.GetBJPKRoomPosMgr().GetClientPos();
		let dunCard1 = cardList[1][count];
		let posID = dunCard1["posID"];
		let cards = dunCard1["cards"];
		this.LogicBJPKGame.SortCardByMin(cards);
		let rankingEnum = dunCard1["rankingEnum"];
		let score = dunCard1["score"];
		let showPos = that.Pos2Show(posID);
		let cardNodeList = that.GetWndNode("allPlayers/pos" + showPos + "/cardList");
		let action = cc.sequence(cc.scaleTo(2, 1, 1), cc.callFunc(function () {
			if (clientPos != posID) {
				for (let i = 0; i < cards.length; i++) {
					// cardNodeList.children[i + 3].scale = 1;
					that.ShowCard(cards[i], cardNodeList.children[i + 3]);
				}
			}
			that.HideOrShowSecondScore(showPos, score, rankingEnum);
			count--;
			that.FaNPaiSecond(count, cardList, playCount, that);
		}));
		for (let j = 3; j < 6; j++) {
			cardNodeList.children[j].runAction(action);
		}
	},
	FaNPaiThird: function (count, cardList, playCount, that) {
		if (count < 0) {
			//显示特殊牌型
			that.ShowSpecialType();
			return;
		}
		let clientPos = this.GetBJPKRoomPosMgr().GetClientPos();
		let dunCard1 = cardList[2][count];
		let posID = dunCard1["posID"];
		let cards = dunCard1["cards"];
		this.LogicBJPKGame.SortCardByMin(cards);
		let rankingEnum = dunCard1["rankingEnum"];
		let score = dunCard1["score"];
		let showPos = that.Pos2Show(posID);
		let cardNodeList = that.GetWndNode("allPlayers/pos" + showPos + "/cardList");
		let action = cc.sequence(cc.scaleTo(2, 1, 1), cc.callFunc(function () {
			if (clientPos != posID) {
				for (let i = 0; i < cards.length; i++) {
					// cardNodeList.children[i + 6].scale = 1;
					that.ShowCard(cards[i], cardNodeList.children[i + 6]);
				}
			}
			that.HideOrShowThirdScore(showPos, score, rankingEnum);
			count--;
			that.FaNPaiThird(count, cardList, playCount, that);
		}));
		for (let j = 6; j < 9; j++) {
			cardNodeList.children[j].runAction(action);
		}
	},*/

	FaNPaiAllFirst: function (clientPos, cardList) {
		for (let i = 0; i < cardList[0].length; i++) {
			let dunCard = cardList[0][i];
			let posID = dunCard["posID"];
			let cards = dunCard["cards"];
			let sortCards = this.GetSortCard(cards);
			let rankingEnum = dunCard["rankingEnum"];
			let score = dunCard["score"];
			let showPos = this.Pos2Show(posID);
			let cardNodeList = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
			if (clientPos != posID) {
				for (let i = 0; i < sortCards.length; i++) {
					// cardNodeList.children[i].scale = 1;
					this.ShowCard(sortCards[i], cardNodeList.children[i]);
				}
			}
			this.HideOrShowFirstScore(showPos, score, rankingEnum);
			let playerSex = this.InitHeroSex(posID);
			let soundName = this.BJPKDefine.SoundPath + playerSex + "/paixing" + rankingEnum + "";
			this.SoundManager.PlaySound(playerSex+"_paixing" + rankingEnum);
		}
		let that = this;
		// this.scheduleOnce(this.FaNPaiAllSecond.bind(null, clientPos, cardList, that), 1.5);
		this.scheduleOnce(this.FaNPaiAllSecond.bind(null, clientPos, cardList, that), 2.5);
	},
	FaNPaiAllSecond: function (clientPos, cardList, that) {
		for (let i = 0; i < cardList[1].length; i++) {
			let dunCard = cardList[1][i];
			let posID = dunCard["posID"];
			let cards = dunCard["cards"];
			let sortCards = that.GetSortCard(cards);
			let rankingEnum = dunCard["rankingEnum"];
			let score = dunCard["score"];
			let showPos = that.Pos2Show(posID);
			let cardNodeList = that.GetWndNode("allPlayers/pos" + showPos + "/cardList");
			if (clientPos != posID) {
				for (let i = 0; i < sortCards.length; i++) {
					// cardNodeList.children[i + 3].scale = 1;
					that.ShowCard(sortCards[i], cardNodeList.children[i + 3]);
				}
			}
			that.HideOrShowSecondScore(showPos, score, rankingEnum);
			let playerSex = that.InitHeroSex(posID);
			let soundName = that.BJPKDefine.SoundPath + playerSex + "/paixing" + rankingEnum + "";
			that.SoundManager.PlaySound(playerSex + "_paixing" + rankingEnum);
		}
		// that.scheduleOnce(that.FaNPaiAllThird.bind(null, clientPos, cardList, that), 1.5);
		that.scheduleOnce(that.FaNPaiAllThird.bind(null, clientPos, cardList, that), 2.5);
	},
	FaNPaiAllThird: function (clientPos, cardList, that) {
		for (let i = 0; i < cardList[2].length; i++) {
			let dunCard = cardList[2][i];
			let posID = dunCard["posID"];
			let cards = dunCard["cards"];
			let sortCards = that.GetSortCard(cards);
			let rankingEnum = dunCard["rankingEnum"];
			let score = dunCard["score"];
			let showPos = that.Pos2Show(posID);
			let cardNodeList = that.GetWndNode("allPlayers/pos" + showPos + "/cardList");
			if (clientPos != posID) {
				for (let i = 0; i < sortCards.length; i++) {
					// cardNodeList.children[i + 6].scale = 1;
					that.ShowCard(sortCards[i], cardNodeList.children[i + 6]);
				}
			}
			that.HideOrShowThirdScore(showPos, score, rankingEnum);
			let playerSex = that.InitHeroSex(posID);
			let soundName = that.BJPKDefine.SoundPath + playerSex + "/paixing" + rankingEnum + "";
			that.SoundManager.PlaySound(playerSex + "_paixing" + rankingEnum);
		}
		// that.scheduleOnce(that.ShowSpecialType, 1);
		that.scheduleOnce(that.ShowSpecialType, 1.5);
	},
	//房间结算
	Event_RoomEnd: function (event) {
		let argDict = event;
		console.log("房间结算Event_RoomEnd", argDict);
		this.roomEnd = true;
		/*let record = argDict["record"];
		let players = record["players"];
		let recordPosInfosList = record["recordPosInfosList"];
		let ownerID = this.GetBJPKRoom().GetRoomProperty("ownerID");
		for (let i = 0; i < recordPosInfosList.length; i++) {
			let recordPosInfos = recordPosInfosList[i];
			let player = players[i];
			if (recordPosInfos["pid"] == player["pid"]) {
				recordPosInfos["name"] = player["name"];
				recordPosInfos["id"] = player["accountID"];
			}
			if (ownerID == recordPosInfos["pid"]) {
				recordPosInfos["isFangZhu"] = true;
			} else {
				recordPosInfos["isFangZhu"] = false;
			}
		}
		/!*let sRoomEndResult = argDict["sRoomEndResult"];
		let setEnd = sRoomEndResult["setEnd"];
		let endTime = sRoomEndResult["endTime"];
		let setId = sRoomEndResult["setId"];
		let countRecords = sRoomEndResult["countRecords"];*!/
		this.FormManager.CloseForm(app.subGameName + "_UISetting02");
		let uiPath = `game/${app.subGameName.toUpperCase()}/ui/UI${app.subGameName.toUpperCase()}DanJu`;
		this.FormManager.ShowForm(uiPath, record);*/
	},
	Event_PosContinueGame: function (event) {
		let argDict = event;
		console.log("继续游戏玩家", argDict);
		let clientPos = this.GetBJPKRoomPosMgr().GetClientPos();
		let posID = argDict["pos"];
		let showPos = this.Pos2Show(posID);
		this.HidePosIconOk(showPos, true);
		if (clientPos == posID) {
			this.HideCaoZuoBtn();
		}
		let room = this.RoomMgr.GetEnterRoom();
		this.ShowPlayerReady(room);
		// this.HidePosSpecialType(showPos);
		// this.HideAllPosScore(showPos);
		// this.HideOrShowPosQiPai(showPos, false);
		/*let cardList = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
		for (let i = 0; i < cardList.children.length; i++) {
			let cardNode = cardList.children[i];
			cardNode.getChildByName("poker_back").active = true;
			cardNode.active = false;
		}*/
	},
	//初始化用户头像
	InitPosHead: function (showPos, data) {
		console.log("InitPosHead", data);
		let posHead = this.allPlayers.getChildByName('pos' + showPos);
		posHead.active = true;
		let touXiang = posHead.getChildByName('touxiang');
		let btn_head = touXiang.getChildByName('btn_head');
		let WeChatHeadImage = btn_head.getComponent(app.subGameName + "_WeChatHeadImage");
		if (data.headImageUrl) {
			WeChatHeadImage.onLoad();
			WeChatHeadImage.ShowHeroHead(data.pid);
		} else {
			btn_head.getComponent(cc.Sprite).spriteFrame = this.default_headIcon;
		}
		let sp_info = touXiang.getChildByName('sp_info');
		sp_info.getChildByName('lb_name').getComponent(cc.Label).string = data.name;
		sp_info.getChildByName('lb_score').getComponent(cc.Label).string = data.point;
		sp_info.getChildByName('lb_sportpoint').active = this.RoomMgr.unionId > 0;
		sp_info.getChildByName('lb_sportpoint').getComponent(cc.Label).string = "赛：" + data.sportsPoint;

		//是否离线
		// touXiang.getChildByName('sp_lixian').active = data.isLostConnect;
		//是否是房主
		this.HideOrShowPosFangZhu(showPos, data.isFangZhu);

		//准备完成ok手势
		let roomReady = data.roomReady;
		posHead.getChildByName("icon_OK").active = !roomReady;
		if (showPos == 1) {
			let zhunBeiBtn = this.GetZhunBeiBtn();
			zhunBeiBtn.active = !roomReady;
			let weiXinBtn = this.GetWeiXinBtn();
			let xianLiaoBtn = this.GetXianLiaoBtn();
			weiXinBtn.active = roomReady;
			xianLiaoBtn.active = roomReady;
		}
		this.HidePosIconOk(showPos, roomReady);
		/*posHead.getChildByName('sp_audio').active = false;
		posHead.getChildByName('sp_chatdi').active = false;*/
	},
	HideAllIconOK: function () {
		let roomPosMgr = this.GetBJPKRoomPosMgr();
		let playerCount = roomPosMgr.GetRoomPlayerCount();
		console.log("HideAllIconOK", playerCount);
		for (let i = 0; i < playerCount; i++) {
			let showPos = this.Pos2Show(i);
			console.log("HideAllIconOKshowPos", showPos);
			this.HidePosIconOk(showPos, false);
		}
	},

	//修改 OK 图标显示
	HidePosIconOk: function (showPos, isReady) {
		let posHead = this.allPlayers.getChildByName('pos' + showPos);
		let icon_OK = posHead.getChildByName("icon_OK");
		icon_OK.active = isReady;
	},

	HideAllLiXian: function () {
		let roomPosMgr = this.GetBJPKRoomPosMgr();
		let playerCount = roomPosMgr.GetRoomPlayerCount();
		for (let i = 0; i < playerCount; i++) {
			let showPos = this.Pos2Show(i);
			if (showPos == 1) {//自己
				continue;
			}
			this.ShowPosLiXian(showPos, false);
		}
	},
	CreateCardNode: function () {
		for (let i = 1; i <= 5; i++) {
			let cardList = this.GetWndNode("allPlayers/pos" + i + "/cardList");
			for (let j = 0; j < 9; j++) {
				let cardNode = cc.instantiate(this.prefab_card);
				cardList.addChild(cardNode);
				/*if (i == 1) {
					cardNode.scaleX = 1;
					cardNode.scaleY = 1;
				} else {
					cardNode.scaleX = 0.8;
					cardNode.scaleY = 0.8;
				}*/
				cardNode.active = false;
			}
		}
	},
	CreateSpecialTypeNode: function () {
		for (let i = 1; i <= 5; i++) {
			let cardList = this.GetWndNode("allPlayers/pos" + i + "/score/cardtypelayout");
			let name = 20;
			for (let j = 0; j < 13; j++) {
				let cardNode = cc.instantiate(this.prefab_specialtype);
				cardNode.name = name + "";
				cardNode.getComponent(cc.Sprite).spriteFrame = this.icon_specialtype[j];
				cardList.addChild(cardNode);
				name++;
			}
		}
	},
	HideAllCardList: function () {
		for (let pos = 1; pos <= 5; pos++) {
			this.HideOrShowPosCardList(pos, false);
			this.HideOrShowPosBiPai(pos, "");
			this.HideOrShowPosQiPai(pos, false);
			this.HideOrShowPosFangZhu(pos, false);
			this.HideAllPosScore(pos);
			this.HidePosSpecialType(pos);
		}
	},
	HideOrShowPosFangZhu: function (showPos, isShow) {
		this.SetWndProperty("allPlayers/pos" + showPos + "/fangzhu", "active", isShow);
	},


	HideAllBiPai: function () {
		for (let pos = 1; pos <= 5; pos++) {
			this.HideOrShowPosBiPai(pos, "");
		}
	},
	HideOrShowPosCardList: function (showPos, isShow) {
		let cardList = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
		cardList.active = isShow;
	},

	//显示棋牌icon 状态
	HideOrShowPosQiPai: function (showPos, isShow) {
		let wndPath = "allPlayers/pos" + showPos + "/img_qp";
		this.SetWndProperty(wndPath, "active", isShow);
	},

	//显示比牌中 和 理牌中 的状态
	HideOrShowPosBiPai: function (showPos, str) {
		let wndPath = "allPlayers/pos" + showPos + "/img_lpd";
		if (str == "") {
			this.SetWndProperty(wndPath, "active", false);
		} else {
			this.SetWndProperty(wndPath, "active", true);
		}
		this.SetWndProperty(wndPath + "/paitip", "text", str);
	},

	HideOrShowFirstScore: function (showPos, score, type) {
		let wndPath = "allPlayers/pos" + showPos + "/score";
		this.SetWndProperty(wndPath, "active", true);
		if (score < 0) {
			this.SetWndProperty(wndPath + "/first/lostcardscore", "text", score);
			this.SetWndProperty(wndPath + "/first/wincardscore", "text", "");
		} else {
			this.SetWndProperty(wndPath + "/first/wincardscore", "text", "+" + score);
			this.SetWndProperty(wndPath + "/first/lostcardscore", "text", "");
		}
		let wndNode = this.GetWndNode(wndPath + "/first/cardtype1");
		wndNode.getComponent(cc.Sprite).spriteFrame = this.typeSpriteFrame[type];
	},

	HideAllScore: function () {
		for (let pos = 1; pos <= 5; pos++) {
			this.HideAllPosScore(pos);
		}
	},

	//设置分数状态为空字符串
	HideAllPosScore: function (showPos) {
		let wndPath = "allPlayers/pos" + showPos + "/score";
		this.SetWndProperty(wndPath + "/first/lostcardscore", "text", "");
		this.SetWndProperty(wndPath + "/first/wincardscore", "text", "");
		let first = this.GetWndNode(wndPath + "/first/cardtype1");
		first.getComponent(cc.Sprite).spriteFrame = "";

		this.SetWndProperty(wndPath + "/second/lostcardscore", "text", "");
		this.SetWndProperty(wndPath + "/second/wincardscore", "text", "");
		let second = this.GetWndNode(wndPath + "/second/cardtype1");
		second.getComponent(cc.Sprite).spriteFrame = "";

		this.SetWndProperty(wndPath + "/third/lostcardscore", "text", "");
		this.SetWndProperty(wndPath + "/third/wincardscore", "text", "");
		let third = this.GetWndNode(wndPath + "/third/cardtype1");
		third.getComponent(cc.Sprite).spriteFrame = "";

		this.SetWndProperty(wndPath + "/allScore/lostcardscore", "text", "");
		this.SetWndProperty(wndPath + "/allScore/wincardscore", "text", "");
	},

	HideOrShowSecondScore: function (showPos, score, type) {
		let wndPath = "allPlayers/pos" + showPos + "/score";
		this.SetWndProperty(wndPath, "active", true);
		if (score < 0) {
			this.SetWndProperty(wndPath + "/second/lostcardscore", "text", score);
			this.SetWndProperty(wndPath + "/second/wincardscore", "text", "");
		} else {
			this.SetWndProperty(wndPath + "/second/wincardscore", "text", "+" + score);
			this.SetWndProperty(wndPath + "/second/lostcardscore", "text", "");
		}
		let wndNode = this.GetWndNode(wndPath + "/second/cardtype1");
		wndNode.getComponent(cc.Sprite).spriteFrame = this.typeSpriteFrame[type];
	},
	HideOrShowThirdScore: function (showPos, score, type) {
		let wndPath = "allPlayers/pos" + showPos + "/score";
		this.SetWndProperty(wndPath, "active", true);
		if (score < 0) {
			this.SetWndProperty(wndPath + "/third/lostcardscore", "text", score);
			this.SetWndProperty(wndPath + "/third/wincardscore", "text", "");
		} else {
			this.SetWndProperty(wndPath + "/third/wincardscore", "text", "+" + score);
			this.SetWndProperty(wndPath + "/third/lostcardscore", "text", "");
		}
		let wndNode = this.GetWndNode(wndPath + "/third/cardtype1");
		wndNode.getComponent(cc.Sprite).spriteFrame = this.typeSpriteFrame[type];
	},
	HideOrShowAllScore: function (showPos, allScore) {
		let wndPath = "allPlayers/pos" + showPos + "/score";
		if (allScore < 0) {
			this.SetWndProperty(wndPath + "/allScore/lostcardscore", "text", allScore);
			this.SetWndProperty(wndPath + "/allScore/wincardscore", "text", "");
		} else {
			this.SetWndProperty(wndPath + "/allScore/wincardscore", "text", "+" + allScore);
			this.SetWndProperty(wndPath + "/allScore/lostcardscore", "text", "");
		}
	},
	ShowSpecialType: function () {
		/*//如果是最后一局显示结算
		if (this.roomEnd) {
			this.ShowDanJuForm();
		} else {
			let rewardsDict = this.GetBJPKRoomSet().GetRoomProperty("rewardsDict");
			for (let posID in rewardsDict) {
				let showPos = this.Pos2Show(posID);
				let rewards = rewardsDict[posID]["rewards"];
				// let score = rewardsDict[posID]["score"];
				let allScore = rewardsDict[posID]["allScore"];
				let roomScore = rewardsDict[posID]["roomScore"];
				this.HideOrShowAllScore(showPos, allScore);
				this.SetPosPoint(showPos, roomScore);
				let wndPath = "allPlayers/pos" + showPos + "/score/cardtypelayout/";
				for (let i = 0; i < rewards.length; i++) {
					let reward = rewards[i];
					this.SetWndProperty(wndPath + reward, "active", true);
				}
				/!*let cardNodeList = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
				for (let j = 0; j < cardNodeList.children.length; j++) {
					// cardNodeList.children[j].removeAllActions();
				}*!/
			}
			this.ShowContinueBtn();
		}*/
		this.unschedule(this.FaNPaiAllSecond);
		this.unschedule(this.FaNPaiAllThird);
		let rewardsDict = this.GetBJPKRoomSet().GetRoomProperty("rewardsDict");
		for (let posID in rewardsDict) {
			let showPos = this.Pos2Show(posID);
			let rewards = rewardsDict[posID]["rewards"];
			// let score = rewardsDict[posID]["score"];
			let allScore = rewardsDict[posID]["allScore"];
			let roomScore = rewardsDict[posID]["roomScore"];
			let sportPoint = rewardsDict[posID]["sportsPoint"];
			this.HideOrShowAllScore(showPos, allScore);
			this.SetPosPoint(showPos, roomScore);
			this.SetWndProperty("allPlayers/pos" + showPos + "/score/lb_sportpoint", "active", this.RoomMgr.unionId > 0);
			this.SetWndProperty("allPlayers/pos" + showPos + "/score/lb_sportpoint", "text", "赛：" + sportPoint);
			if (this.RoomMgr.unionId > 0) {
				let sportPointHead = this.RoomPosMgr.GetPlayerSportsPointByPos(posID);
				// sportPointHead = parseInt(sportPointHead) + parseInt(sportPoint);
				this.SetPosSportPoint(showPos, sportPointHead, true);
			} else {
				this.SetPosSportPoint(showPos, 0);
			}
			let wndPath = "allPlayers/pos" + showPos + "/score/cardtypelayout/";
			for (let i = 0; i < rewards.length; i++) {
				let reward = rewards[i];
				this.SetWndProperty(wndPath + reward, "active", true);
			}
			/*let cardNodeList = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
			for (let j = 0; j < cardNodeList.children.length; j++) {
				// cardNodeList.children[j].removeAllActions();
			}*/
		}
		if (!this.roomEnd) {
			//延迟自动继续
			this.RoomMgr.SendTimeOutContinue();
		}
		this.ShowContinueBtn();
	},
	ShowDanJuForm: function () {
		let roomEnd = this.GetBJPKRoom().GetRoomProperty("roomEnd");
		let record = roomEnd["record"];
		let players = record["players"];
		let recordPosInfosList = record["recordPosInfosList"];
		let ownerID = this.GetBJPKRoom().GetRoomProperty("ownerID");
		for (let i = 0; i < recordPosInfosList.length; i++) {
			let recordPosInfos = recordPosInfosList[i];
			let player = players[i];
			if (recordPosInfos["pid"] == player["pid"]) {
				recordPosInfos["name"] = player["name"];
				recordPosInfos["id"] = player["accountID"];
			}
			if (ownerID == recordPosInfos["pid"]) {
				recordPosInfos["isFangZhu"] = true;
			} else {
				recordPosInfos["isFangZhu"] = false;
			}
		}
		//找出大赢家
		recordPosInfosList.sort((a, b) => {
			return b.point - a.point;
		});
		let max = recordPosInfosList[0].point;
		for (let j = 0; j < recordPosInfosList.length; j++) {
			if (max <= recordPosInfosList[j].point) {
				recordPosInfosList[j]["isWin"] = true;
			} else {
				recordPosInfosList[j]["isWin"] = false;
			}
		}
		let uiPath = `game/${app.subGameName.toUpperCase()}/ui/UI${app.subGameName.toUpperCase()}DanJu`;
		this.FormManager.ShowForm(uiPath, record);
	},
	
	//设置状态？
	HideAllSpecialType: function () {
		for (let showPos = 1; showPos <= 5; showPos++) {
			this.HidePosSpecialType(showPos);
		}
	},
	HidePosSpecialType: function (showPos) {
		let wndPath = "allPlayers/pos" + showPos + "/score/cardtypelayout";
		let wndNode = this.GetWndNode(wndPath);
		for (let j = 0; j < wndNode.children.length; j++) {
			wndNode.children[j].active = false;
		}
		this.SetWndProperty("allPlayers/pos" + showPos + "/score/lb_sportpoint", "text", "");
	},
	//

	ShowPosLiXian: function (showPos, isLiXian) {
		let posHead = this.allPlayers.getChildByName('pos' + showPos);
		let touXiang = posHead.getChildByName('touxiang');
		let sp_lixian = touXiang.getChildByName("sp_lixian");
		sp_lixian.active = isLiXian;
	},
	SetPosPoint: function (showPos, point) {
		let posHead = this.allPlayers.getChildByName('pos' + showPos);
		let touXiang = posHead.getChildByName('touxiang');
		let sp_info = touXiang.getChildByName('sp_info');
		sp_info.getChildByName('lb_score').getComponent(cc.Label).string = point;
	},
	SetPosSportPoint: function (showPos, sportsPoint, isShow = false) {
		let posHead = this.allPlayers.getChildByName('pos' + showPos);
		let touXiang = posHead.getChildByName('touxiang');
		let sp_info = touXiang.getChildByName('sp_info');
		sp_info.getChildByName('lb_sportpoint').getComponent(cc.Label).string = "赛：" + sportsPoint;
		sp_info.getChildByName('lb_sportpoint').active = isShow
	},

	//显示轮到哪家操作的头像动画
	OnShowPosActionHelp: function (waitOpPos) {
		if (waitOpPos == -1) {
			return;
		}
		let showPos = this.Pos2Show(waitOpPos);
		this.AddWndEffect("allPlayer/pos" + showPos + "/touxiang", app.subGameName + "_touxiangkuangtexiao", app.subGameName + "_touxiangkuangtexiao");
	},
	//关闭轮到哪家操作的头像动画
	OnClosePosActionHelp: function (showPos) {
		this.DeleteWndEffect("allPlayer/pos" + showPos + "/touxiang", app.subGameName + "_touxiangkuangtexiao");
	},
	//显示玩家准备状态
	ShowPlayerReady: function (room) {
		if (!room) {
			console.error("Event_ShowReadyOrNoReady not enter room");
			return
		}
		let roomSetID = room.GetRoomProperty("setID");
		let ReadyState = "";
		if (roomSetID > 0) {
			ReadyState = "gameReady";
		} else {
			ReadyState = "roomReady";
		}
		this.SetPlayerReadyInfo(ReadyState);
	},
	//玩家准备状态
	SetPlayerReadyInfo: function (ReadyState) {
		if (ReadyState == "gameReady") {
			//第二局
			this.HideClientReady();
		} else if (ReadyState == "roomReady") {
			//第一局
			if (this.JoinPlayerFinish() && this.IsClientReady(ReadyState) == false) {
				//人数加满，本家没准备
				this.ShowPlayerOk();
			} else if (this.JoinPlayerFinish() && this.IsClientReady(ReadyState) == true) {
				//人数加满，本家准备
				this.HideClientReady();
			} else {
				//人数未满
				this.ShowPlayerYaoQing();
			}
		}
	},
	HideClientReady: function () {
		this.btn_ready.active = 0;
		this.btn_weixin.active = 0;
		this.btn_mowang.active = 0;
		// this.btn_copy.active = 0;
		// this.btn_cancel.active = 0;
		// this.btn_go.active = 0;
		this.invitationNode.active = false;
	},
	JoinPlayerFinish: function () {
		let roomPosMgr = this.RoomMgr.GetEnterRoom().GetRoomPosMgr();
		let playerAll = roomPosMgr.GetRoomAllPlayerInfo();
		let playerAllList = Object.keys(playerAll);
		var tempNum = 0;
		for (let j = 0; j < playerAllList.length; j++) {
			let player = playerAll[playerAllList[j]];
			if (player.pid > 0) {
				tempNum++;
			}
		}
		if (tempNum == playerAllList.length) {
			return true;
		}
		return false;
	},
	IsClientReady: function (ReadyState) {
		let roomPosMgr = this.RoomMgr.GetEnterRoom().GetRoomPosMgr();
		let clientPos = roomPosMgr.GetClientPos();
		let playerAll = roomPosMgr.GetRoomAllPlayerInfo();
		let playerAllList = Object.keys(playerAll);
		for (let i = 0; i < playerAllList.length; i++) {
			let player = playerAll[playerAllList[i]];
			let isClientReady = player[ReadyState];
			if (player["pos"] == clientPos) {
				return isClientReady;
			}
		}

	},
	ShowPlayerOk: function () {
		let room = this.RoomMgr.GetEnterRoom();
		let fangjian = room.GetRoomConfigByProperty("fangjian");
		if (fangjian.indexOf(1) > -1) {
			//自动准备玩法
			this.btn_ready.active = 0;
			this.Click_btn_ready();
		} else {
			//手动准备玩法
			this.btn_ready.active = 1;
		}
		this.invitationNode.active = false;
		this.btn_weixin.active = 0;
		this.btn_mowang.active = 0;
		// this.btn_copy.active = 0;
		// this.btn_cancel.active = 0;
		// this.btn_go.active = 0;
	},
	ShowPlayerYaoQing: function () {
		this.btn_ready.active = false;
		this.btn_weixin.active = 1;
		this.btn_mowang.active = 1;
		// this.btn_copy.active = 1;
		// this.btn_cancel.active = 0;
		// this.btn_go.active = 0;
		if (this.roomCfg.clubId > 0 || this.roomCfg.unionId > 0) {
			this.invitationNode.active = true;
		} else {
			this.invitationNode.active = false;
		}
	},
	//成功退出
	Event_ExitRoomSuccess: function (event) {
		console.log("成功退出Event_ExitRoomSuccess", event);
		let serverPack = event;
		app[app.subGameName + "Client"].ExitGame();
	},
	Event_CodeError: function (event) {
		let argDict = event;
		let code = argDict["Code"];
		if (code == this.ShareDefine.SportsPointNotEnough) {
			this.SetWaitForConfirm("SportsPointNotEnough", this.ShareDefine.ConfirmYN, []);
		} else if (code == this.ShareDefine.NotAllow) {

		}
	},
	Event_SportsPointChange: function (event) {
		console.log("ready状态时竞技点改变", event);
		let pos = event["posId"];
		let showPos = this.Pos2Show(pos);
		let sportPoint = this.RoomPosMgr.GetPlayerSportsPointByPos(pos);
		this.SetPosSportPoint(showPos, sportPoint, true);
	},
	Event_SportsPointEnough: function (event) {
		let msg = event.msg;
		this.SetWaitForConfirm("SportsPointEnough", this.ShareDefine.ConfirmOK, [msg]);
	},
	Event_SportsPointNotEnough: function (event) {
		let msg = event.msg;
		this.SetWaitForConfirm("SportsPointNotEnough", this.ShareDefine.ConfirmYN, []);
	},
	//常用语聊天
	Event_ChatMessage: function (event) {
		let argDict = event;
		console.log("常用语聊天 Event_ChatMessage", argDict);
		let senderPid = argDict["senderPid"];
		let quickID = parseInt(argDict["quickID"]);
		let content = argDict["content"];

		let roomPosMgr = this.GetBJPKRoomPosMgr();
		let playerList = roomPosMgr.GetRoomAllPlayerInfo();
		let playerListKey = Object.keys(playerList);
		let initiatorPos = "";
		for (let i = 0; i < playerListKey.length; i++) {
			let player = playerList[playerListKey[i]];
			let pid = player["pid"];
			if (senderPid == pid) {
				initiatorPos = parseInt(i);
			}
		}
		let playerSex = this.InitHeroSex(initiatorPos);
		let soundName = "";
		let path = "";
		if (quickID < 101) {
			switch (quickID) {
				case 1:
					content = app.i18n.t("UIVoiceStringBieChao");
					soundName = [playerSex, "_FastVoice_1"].join("");
					break;
				case 2:
					content = app.i18n.t("UIVoiceStringBieZou");
					soundName = [playerSex, "_FastVoice_2"].join("");
					break;
				case 3:
					content = app.i18n.t("UIVoiceStringZhaoHu");
					soundName = [playerSex, "_FastVoice_3"].join("");
					break;
				case 4:
					content = app.i18n.t("UIVoiceStringZanLi");
					soundName = [playerSex, "_FastVoice_4"].join("");
					break;
				case 5:
					content = app.i18n.t("UIVoiceStringZanShang");
					soundName = [playerSex, "_FastVoice_5"].join("");
					break;
				case 6:
					content = app.i18n.t("UIVoiceStringCuiCu");
					soundName = [playerSex, "_FastVoice_6"].join("");
					break;
				case 7:
					content = app.i18n.t("UIVoiceStringKuaJiang");
					soundName = [playerSex, "_FastVoice_7"].join("");
					break;
				case 8:
					content = app.i18n.t("UIVoiceStringDaShang");
					soundName = [playerSex, "_FastVoice_8"].join("");
					break;
				case 9:
					content = app.i18n.t("UIVoiceStringLiKai");
					soundName = [playerSex, "_FastVoice_9"].join("");
					break;
				case 10:
					content = app.i18n.t("UIVoiceStringYanChi");
					soundName = [playerSex, "_FastVoice_10"].join("");
					break;
				default:
					console.error("Event_chatmessage not find(%s)", quickID);
			}
		}
		else {
			switch (quickID) {
				case 101:
					path = "face1Action";
					break;
				case 102:
					path = "face2Action";
					break;
				case 103:
					path = "face3Action";
					break;
				case 104:
					path = "face4Action";
					break;
				case 105:
					path = "face5Action";
					break;
				case 106:
					path = "face6Action";
					break;
				case 107:
					path = "face7Action";
					break;
				case 108:
					path = "face8Action";
					break;
				case 109:
					path = "face9Action";
					break;
				case 110:
					path = "face10Action";
					break;
				case 111:
					path = "face11Action";
					break;
				case 112:
					path = "face12Action";
					break;
				case 113:
					path = "face13Action";
					break;
				case 114:
					path = "face14Action";
					break;
				case 115:
					path = "face15Action";
					break;
				case 116:
					path = "face16Action";
					break;
				case 117:
					path = "face17Action";
					break;
				case 118:
					path = "face18Action";
					break;
				case 119:
					path = "face19Action";
					break;
				case 120:
					path = "face20Action";
					break;
				default:
					console.error("Event_chatmessage not find(%s)", quickID);
			}
		}
		this.SoundManager.PlaySound(soundName);

		//敏感词汇替换
		content = this.UtilsWord.CheckContentDirty(content);
		let showPos = this.Pos2Show(initiatorPos);
		let headNode = this.GetWndNode("allPlayers/pos" + showPos);
		if (content == "") {
			this.ShowFaceContent(headNode, path);
		} else {
			this.ShowChatContent(headNode, content);
		}
	},
	Event_GameGift: function (event) {
		let self = this;
		let argDict = event;
		console.log("礼物Event_GameGift", argDict);
		let sendPos = argDict['sendPos'];
		let recivePos = argDict['recivePos'];
		let productId = argDict['productId'];

		let roomPosMgr = this.GetBJPKRoomPosMgr();
		let sendUiPos = roomPosMgr.GetUIPosByDataPos(sendPos);
		let sendHead = this.GetWndNode("allPlayers/pos" + sendUiPos);
		let reciveUiPos = roomPosMgr.GetUIPosByDataPos(recivePos);
		let reciveHead = this.GetWndNode("allPlayers/pos" + reciveUiPos);

		let giftIdx = productId - 1;
		let tempNode = cc.instantiate(this.giftPrefabs[giftIdx]);
		let ani = tempNode.getComponent(cc.Animation);
		// tempNode.tag = giftIdx;
		tempNode.name = ani.defaultClip.name;
		tempNode.bMove = true;
		ani.on('finished', this.OnGiftAniEnd, this);
		let vec1 = sendHead.convertToWorldSpaceAR(cc.v2(0, 0));
		let vec2 = reciveHead.convertToWorldSpaceAR(cc.v2(0, 0));
		vec1 = this.giftNode.convertToNodeSpaceAR(vec1);
		vec2 = this.giftNode.convertToNodeSpaceAR(vec2);
		tempNode.x = vec1.x;
		tempNode.y = vec1.y;
		this.giftNode.addChild(tempNode);
		let action = cc.sequence(
			cc.moveTo(0.3, vec2),
			cc.callFunc(self.GiftMoveEnd, self)
		);
		tempNode.runAction(action);
	},
	GiftMoveEnd: function (sender, useData) {
		sender.getComponent(cc.Animation).play();
		sender.bMove = false;
		//播放音效
		app[app.subGameName + "_SoundManager"]().PlaySound('mofa_' + sender.name);
	},
	OnGiftAniEnd: function (event) {
		let nodes = this.giftNode.children;
		for (let i = nodes.length; i > 0; i--) {
			if (event) {
				let aniState = nodes[i - 1].getComponent(cc.Animation).getAnimationState(nodes[i - 1].name);
				if (aniState.isPlaying) {
					continue;
				}
				if (!nodes[i - 1].bMove) {
					nodes[i - 1].removeFromParent();
				}
			} else {
				nodes[i - 1].removeFromParent();
			}
		}
	},
	InitHeroSex: function (pos) {
		let RoomPosMgr = this.GetBJPKRoomPosMgr();
		let player = RoomPosMgr.GetPlayerInfoByPos(pos);
		let Sex = player["sex"];
		let playerSex = ["boy", "girl"];
		return playerSex[Sex];
	},
	ShowFaceContent: function (headNode, path) {
		headNode.getChildByName('face_ani').active = true;
		var animState = headNode.getChildByName('face_ani').getComponent(cc.Animation).play(path);
		animState.repeatCount = 3;
	},
	ShowChatContent: function (headNode, content) {
		let msgNode = headNode.getChildByName('sp_chatdi').getChildByName('chat_msg');
		let lb_chat = msgNode.getComponent(cc.Label);
		lb_chat.string = content;
		headNode.getChildByName('sp_chatdi').active = true;
		this.scheduleOnce(function () {
			headNode.getChildByName('sp_chatdi').active = false;
		}, 3.5);
	},
	//语音触摸
	//-----------------回调函数------------------
	Event_TouchStart: function (event) {
		app[app.subGameName + "_AudioManager"]().startRecord();

	},
	Event_TouchEnd: function (event) {
		this.FormManager.CloseForm(app.subGameName + "_UIAudio");
		app[app.subGameName + "_AudioManager"]().setTouchEnd(true);
		app[app.subGameName + "_AudioManager"]().stopRecord();
	},
	OnClick: function (btnName, btnNode) {
		if (btnName == "btn_zhunbei") {
			this.Click_btn_ready();
		} else if (btnName == "btn_all_chat") {
			this.FormManager.ShowForm(app.subGameName + "_UIChat");
		} else if (btnName == "btn_set") {
			this.FormManager.ShowForm(app.subGameName + "_UISetting02");
		} else if (btnName == "btn_all_exit" || btnName == "btn_exit") {
			this.Click_btn_exit();
		} else if (btnName == "btn_continue") {
			this.Click_btn_continue();
		} else if (btnName == "btn_weixin") {
			this.click_share('weixin');
		} else if (btnName == "btn_mowang") {
			this.click_share('mowang');
		} else if (btnName == "btn_chuiniu") {
			this.click_share('chuiniu');
		} else if (btnName == "btn_change") {
			this.Click_btn_change();
		} else if (btnName == "btn_head") {
			let roomPosMgr = this.GetBJPKRoomPosMgr();
			let touxiangNode = btnNode.parent;
			let posName = touxiangNode.parent.name;
			let showid = posName.replace('pos', '');
			let touxiangposID = this.Show2Pos(showid);
			if (roomPosMgr.GetPlayerPidByPos(touxiangposID)) {//有玩家在座显示个人信息
				this.FormManager.ShowForm(app.subGameName + "_UIUserInfo", touxiangposID, true);
			} else {
				let roomID = this.RoomMgr.GetEnterRoomID();
				this.RoomMgr.SendSitDown(roomID, touxiangposID);
			}
			console.log("点击头像", showid, touxiangposID);
		} else if (btnName == "btn_all_sx") {
			this.Click_btn_shuaxin();
		}
	},
	/**
	 * 2次确认点击回调
	 * @param curEventType
	 * @param curArgList
	 */
	SetWaitForConfirm: function (msgID, type, msgArg = [], cbArg = []) {
		let ConfirmManager = app[app.subGameName + "_ConfirmManager"]();
		ConfirmManager.SetWaitForConfirmForm(this.OnConFirm.bind(this), msgID, cbArg);
		ConfirmManager.ShowConfirm(type, msgID, msgArg);
	},
	//准备按钮
	Click_btn_ready: function () {
		let room = this.RoomMgr.GetEnterRoom();
		if (!room) {
			console.error("Click_btn_ready not enter room");
			return;
		}
		let roomID = room.GetRoomProperty("roomID");
		let clientPos = room.GetRoomPosMgr().GetClientPos();
		app[app.subGameName + "_GameManager"]().SendReady(roomID, clientPos);
	},
	//游戏开始按钮
	Click_btn_go: function () {
		let roomID = this.RoomMgr.GetEnterRoomID();
		this.RoomMgr.SendStartRoomGame(roomID);
		this.SceneManager.PlayMusic("playmusic", this.BJPKDefine.SoundPath + "playmusic");
	},
	Click_btn_kanPai: function () {
		let roomID = this.RoomMgr.GetEnterRoomID();
		let clientPos = this.GetBJPKRoomPosMgr().GetClientPos();
		this.RoomMgr.SendKanPai(roomID, clientPos);
	},
	//押注
	Click_btn_yaZhu: function (event) {
		console.log("点击押注Click_btn_yaZhu", event.target);
		let node = event.target;
		let name = node.name;
		let value = this.GetNumByJson(name);
		let sendPack = {
			opType: 2,//押注类型
			value: value
		};
		this.RoomMgr.SendOpCard(sendPack);
	},
	// 跟注
	Click_btn_genZhu: function (event) {
		console.log("点击跟注Click_btn_genZhu", event.target);
		let node = event.target;
		let name = node.name;
		let value = this.GetNumByJson(name);
		let sendPack = {
			opType: 3,//跟注类型
			value: value
		};
		this.RoomMgr.SendOpCard(sendPack);
	},
	//弃牌
	Click_btn_qiPai: function () {
		let sendPack = {
			opType: 1//弃牌类型
		};
		this.RoomMgr.SendOpCard(sendPack);
	},
	//开牌
	Click_btn_kaiPai: function () {
		let sendPack = {
			opType: 4//开牌类型
		};
		this.RoomMgr.SendOpCard(sendPack);
	},
	Click_btn_continue: function () {
		if (this.roomEnd) {
			this.ShowDanJuForm();
			return;
		}
		let roomID = this.GetBJPKRoom().GetRoomProperty("roomID");
		app[app.subGameName + "_GameManager"]().SendContinueGame(roomID);
	},
	Click_btn_shuaxin: function () {
		for (let showPos = 1; showPos <=5; showPos++) {
			let cardAniNode = this.GetWndNode("allPlayers/pos" + showPos + "/cardList");
			cardAniNode.getComponent(cc.Animation).stop("cardAni");
			cardAniNode.scaleX = 1;
			cardAniNode.scaleY = 1;
		}
		this.unscheduleAllCallbacks();
		if (this.ShuaXining == true) {
			return;
		}
		this.ShuaXining = true;
		this.ReInRoom();
	},
	ReInRoom: function () {
		let roomID = this.RoomMgr.GetEnterRoomID();
		this.RoomMgr.SendGetRoomInfo(roomID);
	},
	//发送退出房间
	Click_btn_exit: function () {
		let room = this.RoomMgr.GetEnterRoom();
		if (!room) {
			console.error("Click_btn_jiesan not enter room");
			return
		}
		let roomPosMgr = this.RoomMgr.GetEnterRoom().GetRoomPosMgr();
		if (app[app.subGameName + "_ShareDefine"]().isCoinRoom) {
			//Event_ExitRoomSuccess 都有做退出处理
			//Event_CodeError
			// let needArg = roomPosMgr.GetClientPos();
			// let roomID = this.RoomMgr.GetEnterRoomID();
			// app[app.subGameName + "_GameManager"]().SendExitRoom(roomID, needArg);
			// app[app.subGameName + "_FormManager"]().AddDefaultFormName("UIPractice");
			app[app.subGameName + "Client"].ExitGame();
			return;
		}

		let state = room.GetRoomProperty("state");
		if (state == this.ShareDefine.RoomState_End) {
			//直接退出到大厅
			app[app.subGameName + "Client"].ExitGame();
			return
		}
		let ClientPos = roomPosMgr.GetClientPos();
		let player = roomPosMgr.GetPlayerInfoByPos(ClientPos);
		if (!player)
			return;
		let posName = player.name;
		let roomID = this.RoomMgr.GetEnterRoomID();
		if (state == this.ShareDefine.RoomState_Playing) {
			let jiesan = room.GetRoomConfigByProperty("jiesan");
			if (jiesan == 4) {
				this.ShowSysMsg("当前房间不可解散");
				return;
			}
			app[app.subGameName + "_GameManager"]().SendDissolveRoom(roomID, posName);
			return
		}

		let msgID = '';

		let roomCfg = room.GetRoomConfig();
		if (roomCfg.createType == 2 || roomCfg.clubId != 0) {
			msgID = 'UIMoreTuiChuFangJian';
		} else {
			if (room.IsClientIsCreater()) {
				msgID = 'PlayerLeaveRoom';
			}
			else {
				msgID = 'UIMoreTuiChuFangJian';
			}
		}

		app[app.subGameName + "_ConfirmManager"]().SetWaitForConfirmForm(this.OnConFirm.bind(this), msgID, []);
		app[app.subGameName + "_ConfirmManager"]().ShowConfirm(this.ShareDefine.Confirm, msgID, []);
	},
	/**
	 * 2次确认点击回调
	 * @param curEventType
	 * @param curArgList
	 */
	OnConFirm: function (clickType, msgID, backArgList) {
		let room = this.RoomMgr.GetEnterRoom();
		if (clickType != "Sure") {
			if (msgID == "SportsPointNotEnough") {
				let roomID = this.RoomMgr.GetEnterRoomID();
				app[app.subGameName + "_GameManager"]().SendDissolveRoom(roomID);
			}
			return
		}
		if (msgID == "PlayerLeaveRoom") {
			let roomID = this.RoomMgr.GetEnterRoomID();
			app[app.subGameName + "_GameManager"]().SendDissolveRoom(roomID);
		} else if (msgID == "UIPlay_BeKick") {
			app[app.subGameName + "Client"].ExitGame();
		} else if (msgID == "OwnnerForceRoom") {
			app[app.subGameName + "Client"].ExitGame();
		} else if (msgID == "DissolveRoom") {
			//特殊处理，需要显示单局结算，不能退出
			app[app.subGameName + "Client"].ExitGame();
		} else if (msgID == "MSG_BeKick" || msgID == "MSG_BeDissolve") {
			app[app.subGameName + "Client"].ExitGame();
		} else if (msgID == "UIMoreTuiChuFangJian") {
			let roomPosMgr = this.RoomMgr.GetEnterRoom().GetRoomPosMgr();
			let ClientPos = roomPosMgr.GetClientPos();
			let player = roomPosMgr.GetPlayerInfoByPos(ClientPos);
			if (!player)
				return;
			let posName = player.name;
			let roomID = this.RoomMgr.GetEnterRoomID();
			let state = room.GetRoomProperty("state");
			if (state == this.ShareDefine.RoomState_Playing) {
				app[app.subGameName + "_GameManager"]().SendDissolveRoom(roomID, posName);
				return
			}
			//房主不能退出房间，只能解散
			if (this.RoomMgr.GetEnterRoom().IsClientIsOwner()) {
				app[app.subGameName + "_GameManager"]().SendDissolveRoom(roomID, posName);
				return
			}
			app[app.subGameName + "_GameManager"]().SendExitRoom(roomID, ClientPos);
		}
	},
	GetWeiXinBtn: function () {
		let weiXinBtn = this.btn_caoZuoContainer.getChildByName("btn_weixin");
		return weiXinBtn;
	},
	GetXianLiaoBtn: function () {
		let xianLiaoBtn = this.btn_caoZuoContainer.getChildByName("btn_mowang");
		return xianLiaoBtn;
	},

	//操作按钮（设置、 刷新、等）
	GetExitBtn: function () {
		let exitBtn = this.GetWndNode("roomBtnContainer/btn_all_exit");
		return exitBtn;
	},
	GetZhunBeiBtn: function () {
		let zhunBeiBtn = this.btn_caoZuoContainer.getChildByName("btn_zhunbei");
		return zhunBeiBtn;
	},
	GetGoBtn: function () {
		let goBtn = this.btn_caoZuoContainer.getChildByName("btn_go");
		return goBtn;
	},
	GetJieSanBtn: function () {
		let jieSanBtn = this.btn_caoZuoContainer.getChildByName("btn_exit");
		return jieSanBtn;
	},
	GetContinueBtnBtn: function () {
		let continueBtn = this.btn_caoZuoContainer.getChildByName("btn_continue");
		return continueBtn;
	},
	GetJiaYiBtn: function () {
		let jiaYiBtn = this.btn_caoZuoContainer.getChildByName("btn_jiaYi");
		return jiaYiBtn;
	},
	GetJiaErBtn: function () {
		let jiaErBtn = this.btn_caoZuoContainer.getChildByName("btn_jiaEr");
		return jiaErBtn;
	},
	GetClientPos: function () {
		let clientPos = this.GetBJPKRoomPosMgr().GetClientPos();
		return clientPos;
	},
	GetBJPKRoomSet: function () {
		let roomSet = this.GetBJPKRoom().GetRoomSet();
		return roomSet;
	},
	GetBJPKRoomPosMgr: function () {
		let roomPosMgr = this.GetBJPKRoom().GetRoomPosMgr();
		return roomPosMgr;
	},
	GetBJPKRoom: function () {
		let room = this.RoomMgr.GetEnterRoom();
		return room;
	},
	GetNumByJson: function (string) {
		let num = string.replace(/[^0-9]/ig, "");
		return num;
	},
	OnUpdate: function () {
		//更新系统时间
		var DateNow = new Date();
		let Months = DateNow.getMonth() + 1;
		let Dates = DateNow.getDate();
		let Hours = DateNow.getHours();
		let Minutes = DateNow.getMinutes();
		let Seconds = DateNow.getSeconds();
		Months = this.ComTool.StringAddNumSuffix("", Months, 2);
		Dates = this.ComTool.StringAddNumSuffix("", Dates, 2);
		Hours = this.ComTool.StringAddNumSuffix("", Hours, 2);
		Minutes = this.ComTool.StringAddNumSuffix("", Minutes, 2);
		Seconds = this.ComTool.StringAddNumSuffix("", Seconds, 2);
		// let nowTime = this.node.getChildByName("right_top").getChildByName("nowtime");
		// nowTime.getComponent(cc.Label).string = Hours + ":" + Minutes;
		let str = Months + "/" + Dates + "  " + Hours + ":" + Minutes + ":" + Seconds;
		this.SetWndProperty("roomInfo/lb_time", "text", str);
	},
});